package com.makemoney.miniprogram.common.consts;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;

public enum GenderEnum {
    UNKNOWN(0, "未知"),
    MALE(1, "男"),
    FEMALE(2, "女");

    @EnumValue
    private final int value;
    private final String name;

    private GenderEnum(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public static GenderEnum valueOf(Integer value) {
        if(ObjectUtil.isNull(value)){
            return null;
        }
        for(GenderEnum genderEnum : GenderEnum.values()){
            if(value == genderEnum.getValue()){
                return genderEnum;
            }
        }
        return null;
    }

    public static GenderEnum valueOf2(String name) {
        if(StrUtil.isEmpty(name)){
            return null;
        }
        for(GenderEnum genderEnum : GenderEnum.values()){
            if(genderEnum.getName().equals(name)){
                return genderEnum;
            }
        }
        return null;
    }


    @Override
    public String toString() {
        return "GenderEnum{" +
                "value=" + this.getValue() +
                ",name=" + this.getName() +
                '}';
    }
}
